const fs = require('fs');
const ini = require('ini');
const iconv = require('iconv-lite');

function loadIni(filename, encoding = "gb2312") {
    const buffer = fs.readFileSync(filename)
    return ini.parse(iconv.decode(buffer, encoding))
}
function saveIni(filename, obj, encoding = "gb2312") {
    const encoded = iconv.encode(ini.stringify(obj), encoding)
    fs.writeFileSync(filename, encoded, { encoding: 'binary' })
}


module.exports = { loadIni, saveIni };